using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class Tf_attend {
		#region Fields
		private int uid;
		private int ehId;
		private DateTime keyin_date = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the Tf_attend class.
		/// </summary>
		public Tf_attend() {
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_attend class.
		/// </summary>
		public Tf_attend(int uid, int ehId, DateTime keyin_date) {
			this.uid = uid;
			this.ehId = ehId;
			this.keyin_date = keyin_date;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Uid value.
		/// </summary>
		public int Uid {
			get { return uid; }
			set { uid = value; }
		}
		
		/// <summary>
		/// Gets or sets the EhId value.
		/// </summary>
		public int EhId {
			get { return ehId; }
			set { ehId = value; }
		}
		
		/// <summary>
		/// Gets or sets the Keyin_date value.
		/// </summary>
		public DateTime Keyin_date {
			get { return keyin_date; }
			set { keyin_date = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the tf_attend table.
		/// </summary>
		public void Insert() {
			SqlClientUtility.ExecuteNonQuery("tf_attendInsert", uid, ehId, keyin_date);
		}
		
		/// <summary>
		/// Updates a record in the tf_attend table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("tf_attendUpdate", uid, ehId, keyin_date);
		}
		
		/// <summary>
		/// Deletes a record from the tf_attend table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("tf_attendDelete", uid, ehId);
		}
		
		/// <summary>
		/// Selects a single record from the tf_attend table.
		/// </summary>
		public static Tf_attend Select(int uid, int ehId) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_attendSelect", uid, ehId)) {
				if (dataReader.Read()) {
					return MakeTf_attend(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the tf_attend table.
		/// </summary>
		public static List<Tf_attend> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_attendSelectAll")) {
				List<Tf_attend> tf_attendList = new List<Tf_attend>();
				while (dataReader.Read()) {
					Tf_attend tf_attend = MakeTf_attend(dataReader);
					tf_attendList.Add(tf_attend);
				}
				return tf_attendList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the tf_attend class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static Tf_attend MakeTf_attend(SqlDataReader dataReader) {
			Tf_attend tf_attend = new Tf_attend();
			
			if (dataReader.IsDBNull(0) == false) {
				tf_attend.Uid = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tf_attend.EhId = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tf_attend.Keyin_date = dataReader.GetDateTime(2);
			}

			return tf_attend;
		}
		#endregion
	}
}
